local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local d = ls.dynamic_node
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local rep = require("luasnip.extras").rep

local line_begin = require("luasnip.extras.expand_conditions").line_begin

local helpers = require("luasnip_helpers")
local in_text = helpers.in_text

return {
    s(
        { trig = "frame", dscr = "Align equations", snippetType = "autosnippet" },
        fmta(
            [[
                \begin{frame}
                \frametitle{<>}
                    <>
                \end{frame}
            ]],
            { 
                i(1),
                i(2),
            }
        ),
        { condition = line_begin * in_text }
    ),
    s(
        { trig = "doca", dscr = "document template", snippetType = "autosnippet" },
        fmta(
            [[
                % !TEX program = xelatex
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Define Article %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \documentclass{article}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \usepackage{ctex}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Using Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \usepackage{geometry}
                \usepackage{graphicx}
                \usepackage{amssymb}
                \usepackage{amsmath}
                \usepackage{amsthm}
                \usepackage{empheq}
                \usepackage{mdframed}
                \usepackage{booktabs}
                \usepackage{lipsum}
                \usepackage{graphicx}
                \usepackage{color}
                \usepackage{psfrag}
                \usepackage{pgfplots}
                \usepackage{bm}
                \usepackage{longdivision}
                \usepackage{polynom}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                % Other Settings
                %%%%%%%%%%%%%%%%%%%%%%%%%% Page Setting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \geometry{a4paper}

                %%%%%%%%%%%%%%%%%%%%%%%%%% Define some useful colors %%%%%%%%%%%%%%%%%%%%%%%%%%
                \definecolor{ocre}{RGB}{243,102,25}
                \definecolor{mygray}{RGB}{243,243,244}
                \definecolor{deepGreen}{RGB}{26,111,0}
                \definecolor{shallowGreen}{RGB}{235,255,255}
                \definecolor{deepBlue}{RGB}{61,124,222}
                \definecolor{shallowBlue}{RGB}{235,249,255}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %%%%%%%%%%%%%%%%%%%%%%%%%% Define an orangebox command %%%%%%%%%%%%%%%%%%%%%%%%
                \newcommand\orangebox[1]{\fcolorbox{ocre}{mygray}{\hspace{1em}#1\hspace{1em}}}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %%%%%%%%%%%%%%%%%%%%%%%%%%%% English Environments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \newtheoremstyle{mytheoremstyle}{3pt}{3pt}{\normalfont}{0cm}{\rmfamily\bfseries}{}{1em}{{\color{black}\thmname{#1}~\thmnumber{#2}}\thmnote{\,--\,#3}}
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowGreen,linecolor=deepGreen,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{theorem}{定理}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowGreen,linecolor=deepGreen,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{axiom}{公理}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowBlue,linecolor=deepBlue,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{definition}{定义}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowBlue,linecolor=deepBlue,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{problem}{例}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowBlue,linecolor=deepBlue,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{corollary}{推论}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowBlue,linecolor=deepBlue,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{example}{例}[section]
                \theoremstyle{mytheoremstyle}
                \newmdtheoremenv[linewidth=1pt,backgroundcolor=shallowBlue,linecolor=deepBlue,leftmargin=0pt,innerleftmargin=20pt,innerrightmargin=20pt,]{lemma}{引理}[section]
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting Settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \usepgfplotslibrary{colorbrewer}
                \pgfplotsset{width=8cm,compat=1.9}
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Title & Author %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                \title{ <> }
                \author{ <> }
                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


                \begin{document}
                    \maketitle

                    <>

                \end{document}
            ]],
            {
                i(1),
                i(2),
                i(3),
            }
        ),
        { condition = line_begin * in_text }
    ),
}
